package com.firefly.service.query.cms;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.firefly.dao.dao.cms.po.LinkTypePo;
import com.firefly.dao.dao.cms.service.LinkTypeService;
import com.firefly.dao.assembler.cms.LinkTypeAssembler;
import com.firefly.dao.dto.CommonDto;
import com.firefly.dao.dto.cms.LinkTypeSearchDto;
import com.firefly.dao.vo.CommonListVo;
import com.firefly.dao.vo.cms.LinkTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description: 链接分类
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/12/20
 **/
@Service
public class LinkTypeQuery {
    private final LinkTypeAssembler linkTypeAssembler;
    private final LinkTypeService linkTypeService;
    @Autowired
    public LinkTypeQuery(LinkTypeAssembler linkTypeAssembler,LinkTypeService linkTypeService){
        this.linkTypeAssembler = linkTypeAssembler;
        this.linkTypeService = linkTypeService;
    }

    // 获取列表
    public CommonListVo getList(LinkTypeSearchDto request) {
        QueryWrapper<LinkTypePo> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(!request.key.isBlank(), "name", request.key).eq("del_flag",0);
        Long count = linkTypeService.count(queryWrapper);
        queryWrapper.last("limit " + request.offset + "," + request.pageSize).orderByDesc("id");
        List<LinkTypePo> list = linkTypeService.list(queryWrapper);
        CommonListVo result = new CommonListVo();
        result.setList(linkTypeAssembler.getListVo(list));
        result.setCount(count);
        return result;
    }

    public LinkTypeVo getDetail(CommonDto request){
        return linkTypeAssembler.getVo(linkTypeService.getById(request.detailId));
    }
}
